#import <Foundation/Foundation.h>
#import "GamePeer.h"


@class GameClient, NetServiceBrowser;

@protocol GameClientDelegate <NSObject>
@optional
- (void) gameClientDidStartDiscoveringServers:(GameClient*)client;
- (void) gameClientDidUpdateOnlineServers:(GameClient*)client;
- (void) gameClientWillStopDiscoveringServers:(GameClient*)client;
@end

/*
The original implementation of this class did more than this version does, so it's important not
to get them confused. This class handles the discovery of servers on the network. It keeps an array
of the servers it can see (_onlineServers). It doesn't manage the communication with those servers,
though. I didn't feel like that made sense, because we often work with multiple servers and we need
them to be tied directly to instances of DrawingPeerContributor. I started building a crazy delegate chain
to get the data to the right place, and realized it was rediculous.
The "identifier" must be unique to your game and can only be made of the "a-z", "A-Z", "0-9", "." or "-" characters
*/

@interface GameClient : NSObject
{
@private
    NSObject<GameClientDelegate>*   _delegate;
	
	CFMutableDictionaryRef          _onlineServers;
	NetServiceBrowser*              _browser;
    BOOL                            _initBrowserComplete;
}

@property(readonly, getter=isDiscoveringServers) BOOL discoveringServers;
@property(readonly) NSArray* onlineServers;

- (id)init;
- (void)setDelegate:(NSObject<GameClientDelegate>*)d;

/* These functions provide the basis for the zero-config networking. They have been further abstracted for use
with this program. To start networking, use the DataManager's functions (which start both client & server). 
It should not be necessary to call these separately. */
- (BOOL)startDiscoveringServersWithIdentifier:(NSString*)identifier;
- (void)stopDiscoveringServers;

@end
